<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>123</h1>
  <h2>456</h2>
  <h1>789</h1>
</body>
<script>
  const bodyConent=document.body.innerHTML;
  let reg=/<(h[1-6])>([\s\S]+?)<\/\1>/ig
  let result= bodyConent.matchAll(reg)
  let lists=[]
  for(const item of result){
    lists.push(item[2])
  }
  console.table(lists);
  
</script>

</html>